﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StockFinder.Model
{
    public class WeeklyPrice
    {
        public DailyPrice Monday { get; set; }
        public DailyPrice Tuesday { get; set; }
        public DailyPrice Wednesday { get; set; }
        public DailyPrice Thursday { get; set; }
        public DailyPrice Friday { get; set; }

        public int WeekOfYear { get; set; }
        public int Year { get; set; }

        /// <summary>
        /// Gets the adjusted weekly high price
        /// </summary>
        /// <returns></returns>
        public decimal GetWeeklyHigh()
        {
            decimal weeklyHigh = 0.0M;

            if (Monday != null && Monday.AdjustedHigh > 0)
            {
                weeklyHigh = Monday.AdjustedHigh;
            }

            if (Tuesday != null && Tuesday.AdjustedHigh > 0)
            {
                if (Tuesday.AdjustedHigh > weeklyHigh)
                {
                    weeklyHigh = Tuesday.AdjustedHigh;
                }
            }

            if (Wednesday != null && Wednesday.AdjustedHigh > 0)
            {
                if (Wednesday.AdjustedHigh > weeklyHigh)
                {
                    weeklyHigh = Wednesday.AdjustedHigh;
                }
            }

            if (Thursday != null && Thursday.AdjustedHigh > 0)
            {
                if (Thursday.AdjustedHigh > weeklyHigh)
                {
                    weeklyHigh = Thursday.AdjustedHigh;
                }
            }

            if (Friday != null && Friday.AdjustedHigh > 0)
            {
                if (Friday.AdjustedHigh > weeklyHigh)
                {
                    weeklyHigh = Friday.AdjustedHigh;
                }
            }

            return weeklyHigh;
        }

        /// <summary>
        /// Gets the adjusted weekly low price
        /// </summary>
        /// <returns></returns>
        public decimal GetWeeklyLow()
        {
            decimal weeklyLow = 0.0M;

            if (Monday != null && Monday.AdjustedLow > 0)
            {
                weeklyLow = Monday.AdjustedLow;
            }

            if (Tuesday != null && Tuesday.AdjustedLow > 0)
            {
                if (Tuesday.AdjustedLow < weeklyLow || weeklyLow == 0.0M)
                {
                    weeklyLow = Tuesday.AdjustedLow;
                }
            }

            if (Wednesday != null && Wednesday.Low > 0)
            {
                if (Wednesday.AdjustedLow < weeklyLow || weeklyLow == 0.0M)
                {
                    weeklyLow = Wednesday.AdjustedLow;
                }
            }

            if (Thursday != null && Thursday.AdjustedLow > 0)
            {
                if (Thursday.AdjustedLow < weeklyLow || weeklyLow == 0.0M)
                {
                    weeklyLow = Thursday.AdjustedLow;
                }
            }

            if (Friday != null && Friday.AdjustedLow > 0)
            {
                if (Friday.AdjustedLow < weeklyLow || weeklyLow == 0.0M)
                {
                    weeklyLow = Friday.AdjustedLow;
                }
            }

            return weeklyLow;
        }

        /// <summary>
        /// Gets the adjusted open price for the week
        /// </summary>
        /// <returns></returns>
        public decimal GetWeeklyOpen()
        {
            decimal weeklyOpen = 0.0M;

            if (Friday != null)
            {
                weeklyOpen = Friday.AdjustedOpen;
            }

            if (Thursday != null)
            {
                weeklyOpen = Thursday.AdjustedOpen;
            }

            if (Wednesday != null)
            {
                weeklyOpen = Wednesday.AdjustedOpen;
            }

            if (Tuesday != null)
            {
                weeklyOpen = Tuesday.AdjustedOpen;
            }

            if (Monday != null)
            {
                weeklyOpen = Monday.AdjustedOpen;
            }

            return weeklyOpen;
        }

        /// <summary>
        /// Gets the weekly adjusted close price
        /// </summary>
        /// <returns></returns>
        public decimal GetWeeklyClose()
        {
            decimal weeklyClose = 0.0M;

            if (Monday != null)
            {
                weeklyClose = Monday.AdjustedClose;
            }

            if (Tuesday != null)
            {
                weeklyClose = Tuesday.AdjustedClose;
            }

            if (Wednesday != null)
            {
                weeklyClose = Wednesday.AdjustedClose;
            }

            if (Thursday != null)
            {
                weeklyClose = Thursday.AdjustedClose;
            }

            if (Friday != null)
            {
                weeklyClose = Friday.AdjustedClose;
            }

            return weeklyClose;
        }
    }
}
